package com.link.ppt.Model.Impl;

import com.link.ppt.Api.PPTService;
import com.link.ppt.Model.Bean.BaseBean;
import com.link.ppt.Model.Bean.KeywordsBean;
import com.link.ppt.Model.Bean.PPTBean;
import com.link.ppt.Model.Bean.PPTDetailBean;
import com.link.ppt.Model.Bean.PPTResponseBean;
import com.link.ppt.Model.Bean.ScorePPT;
import com.link.ppt.Model.IPPTModel;
import com.link.ppt.Utils.ServiceFactory;
import com.link.ppt.Utils.TransformUtils;

import java.util.HashMap;
import java.util.Map;

import okhttp3.RequestBody;
import rx.Observable;

/**
 * Created by liucxu on 2018/1/29.
 */

public class PPTModelImpl implements IPPTModel {

    /**
     * 获取PPT列表
     *
     * @param keyWord
     * @param pageNum
     * @return
     */
    @Override
    public Observable<PPTBean> RequestPPTStream(String keyWord, int pageNum) {
        HashMap<String, String> params = new HashMap<>();
        params.put("task", "querPPTList");
        params.put("keyWord", keyWord);
        params.put("pageNum", pageNum + "");
        return ServiceFactory.GetInstance().createService(PPTService.class).RequestPPTStream(params).compose(TransformUtils.<PPTBean>defaultSchedulers());
    }

    @Override
    public Observable<PPTBean> RequestMyPublishStorePPTStream(int pageNum, boolean isMyPublish) {
        HashMap<String, String> params = new HashMap<>();
        if (isMyPublish) {
            params.put("task", "querMyPPTList");
        } else {
            params.put("task", "querFavPPTList");
        }
        params.put("pageNum",pageNum+"");
        return ServiceFactory.GetInstance().createService(PPTService.class).RequestMyPublishStorePPTStream(params).compose(TransformUtils.<PPTBean>defaultSchedulers());
    }

    @Override
    public Observable<ScorePPT> LikePPTPoint(int point, String ppid) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","likePPT");
        params.put("point",point+"");
        params.put("pptId",ppid);
        return ServiceFactory.GetInstance().createService(PPTService.class).LikePPTPoint(params).compose(TransformUtils.<ScorePPT>defaultSchedulers());
    }

    @Override
    public Observable<PPTDetailBean> QueryPPTDetail(String pptId) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","queryPPTDetail");
        params.put("pptId",pptId);
        return ServiceFactory.GetInstance().createService(PPTService.class).QueryPPTDetail(params).compose(TransformUtils.<PPTDetailBean>defaultSchedulers());
    }

    @Override
    public Observable<BaseBean> FavPPT(String pptId, boolean isFav) {
        HashMap<String,String> params=new HashMap<>();
        if(isFav){
            params.put("task", "favPPT");
        }
        else{
            params.put("task", "disFavPPT");
        }
        params.put("pptId", pptId);
        return ServiceFactory.GetInstance().createService(PPTService.class).FavPPT(params).compose(TransformUtils.<BaseBean>defaultSchedulers());
    }

    /**
     * 举报PPT
     * @param pptId
     * @return
     */
    @Override
    public Observable<BaseBean> ReportPPT(String pptId) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task", "jubaoPPT");
        params.put("pptId", pptId);
        return ServiceFactory.GetInstance().createService(PPTService.class).ReportPPT(params).compose(TransformUtils.<BaseBean>defaultSchedulers());
    }

    /**
     * 订阅
     * @param toUserId
     * @return
     */
    @Override
    public Observable<BaseBean> SubscribePPT(String toUserId) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task", "subscribePPTUser");
        params.put("toUserId", toUserId);
        return ServiceFactory.GetInstance().createService(PPTService.class).SubscribePPT(params).compose(TransformUtils.<BaseBean>defaultSchedulers());
    }

    /**
     * 删除PPT
     * @param pptId
     * @return
     */
    @Override
    public Observable<BaseBean> DeletePPT(String pptId) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task", "deletePPT");
        params.put("pptId", pptId);
        return ServiceFactory.GetInstance().createService(PPTService.class).DeletePPT(params).compose(TransformUtils.<BaseBean>defaultSchedulers());
    }

    @Override
    public Observable<BaseBean> PublishPPTUrl(String pptUrl) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task", "postPPTUrl");
        params.put("pptUrl", pptUrl);
        return ServiceFactory.GetInstance().createService(PPTService.class).PublishPPTUrl(params).compose(TransformUtils.<BaseBean>defaultSchedulers());
    }

    @Override
    public Observable<BaseBean> CommonRequest(HashMap<String, String> params) {
        return ServiceFactory.GetInstance().createService(PPTService.class).CommonRequest(params).compose(TransformUtils.<BaseBean>defaultSchedulers());
    }

    @Override
    public Observable<PPTResponseBean> RequestImageId(HashMap<String, String> params) {
        return ServiceFactory.GetInstance().createService(PPTService.class).RequestImageId(params).compose(TransformUtils.<PPTResponseBean>defaultSchedulers());
    }

    @Override
    public Observable<BaseBean> PublishPPTWithPic(Map<String, RequestBody> params) {
        return ServiceFactory.GetInstance().createService(PPTService.class).PublishPPTWithPic(params).compose(TransformUtils.<BaseBean>defaultSchedulers());
    }

    /**
     * 获取首页热词推荐
     * @return
     */
    @Override
    public Observable<KeywordsBean> RequestHotKeywords() {
        HashMap<String,String> params=new HashMap<>();
        params.put("task", "queryKeyWordList");
        return ServiceFactory.GetInstance().createService(PPTService.class).RequestHotKeywords(params).compose(TransformUtils.<KeywordsBean>defaultSchedulers());
    }
}
